package com.supermarket.web.controller.supermarket;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.supermarket.business.domain.SupermarketSupplier;
import com.supermarket.business.dto.SupermarketSupplierDTO;
import com.supermarket.business.vo.SupermarketSupplierVO;
import org.springframework.beans.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.supermarket.common.annotation.Log;
import com.supermarket.common.core.controller.BaseController;
import com.supermarket.common.core.domain.AjaxResult;
import com.supermarket.common.enums.BusinessType;
import com.supermarket.business.service.ISupermarketSupplierService;
import com.supermarket.common.utils.poi.ExcelUtil;
import com.supermarket.common.core.page.TableDataInfo;

/**
 * 供应商Controller
 * 
 * @author ruoyi
 * @date 2025-07-21
 */
@RestController
@RequestMapping("/supermarket/supplier")
public class SupermarketSupplierController extends BaseController
{
    @Resource
    private ISupermarketSupplierService sysSupplierService;

    /**
     * 查询供应商列表
     */
    @PreAuthorize("@ss.hasPermi('supermarket:supplier:list')")
    @GetMapping("/list")
    public TableDataInfo list(SupermarketSupplierDTO supermarketSupplierDTO)
    {
        startPage();
        SupermarketSupplier supermarketSupplier = new SupermarketSupplier();
        BeanUtils.copyProperties(supermarketSupplierDTO, supermarketSupplier);
        List<SupermarketSupplier> list = sysSupplierService.selectSysSupplierList(supermarketSupplier);
        return getDataTable(list);
    }

    /**
     * 导出供应商列表
     */
    @PreAuthorize("@ss.hasPermi('supermarket:supplier:export')")
    @Log(title = "供应商", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SupermarketSupplier supermarketSupplier)
    {
        List<SupermarketSupplier> list = sysSupplierService.selectSysSupplierList(supermarketSupplier);
        ExcelUtil<SupermarketSupplier> util = new ExcelUtil<SupermarketSupplier>(SupermarketSupplier.class);
        util.exportExcel(response, list, "供应商数据");
    }

    /**
     * 获取供应商详细信息
     */
    @PreAuthorize("@ss.hasPermi('supermarket:supplier:query')")
    @GetMapping(value = "/{supplierId}")
    public AjaxResult getInfo(@PathVariable("supplierId") Long supplierId)
    {
        return success(sysSupplierService.selectSysSupplierVOBySupplierId(supplierId));
    }

    /**
     * 新增供应商
     */
    @PreAuthorize("@ss.hasPermi('supermarket:supplier:add')")
    @Log(title = "供应商", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SupermarketSupplierDTO supermarketSupplierDTO)
    {
        SupermarketSupplier supermarketSupplier = new SupermarketSupplier();
        BeanUtils.copyProperties(supermarketSupplierDTO, supermarketSupplier);
        return toAjax(sysSupplierService.insertSysSupplier(supermarketSupplier));
    }

    /**
     * 修改供应商
     */
    @PreAuthorize("@ss.hasPermi('supermarket:supplier:edit')")
    @Log(title = "供应商", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SupermarketSupplierDTO supermarketSupplierDTO)
    {
        SupermarketSupplier supermarketSupplier = new SupermarketSupplier();
        BeanUtils.copyProperties(supermarketSupplierDTO, supermarketSupplier);
        return toAjax(sysSupplierService.updateSysSupplier(supermarketSupplier));
    }

    /**
     * 删除供应商
     */
    @PreAuthorize("@ss.hasPermi('supermarket:supplier:remove')")
    @Log(title = "供应商", businessType = BusinessType.DELETE)
	@DeleteMapping("/{supplierIds}")
    public AjaxResult remove(@PathVariable Long[] supplierIds)
    {
        return toAjax(sysSupplierService.deleteSysSupplierBySupplierIds(supplierIds));
    }
}
